// data/local/dao/SavedGameDao.kt
package com.hwpt.chesedemo.data.local.dao

import androidx.room.*
import com.hwpt.chesedemo.data.local.entity.GameRecordEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface SavedGameDao {
    
    @Query("SELECT * FROM saved_games ORDER BY createdAt DESC")
    fun getAllGames(): Flow<List<GameRecordEntity>>
    
    @Query("SELECT * FROM saved_games WHERE id = :gameId")
    suspend fun getGameById(gameId: String): GameRecordEntity?
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertGame(game: GameRecordEntity)
    
    @Delete
    suspend fun deleteGame(game: GameRecordEntity)
    
    @Query("DELETE FROM saved_games WHERE id = :gameId")
    suspend fun deleteGameById(gameId: String)
    
    @Query("SELECT COUNT(*) FROM saved_games")
    suspend fun getGameCount(): Int
}